How can I get the content from a session variable? - session

My situation:
On my jsp site I show a table. When somebody click a row, this row must be marked with an other backround color for example. Also more then one row can be marked. Two things are important.
First: I bear in mind which rows are marked.
Secend: In which order.
My idea is:
I have a ArrayList and put all row IDs in this. So I solve both problems. Now I put this ArrayList in the session for the next click and the row ID ( req.getSession().setAttribute(req.getParameter("rowID") , ""+arrayList.size()); ) for the jsp file.
My problem in jsp file:
I don't now what's called session variable name.
if this rowId alrady clicked?
..
I have got only the bean name. How can I get the content from the session, if exact this line must be marked?
Normally I set a session variable so: req.getSession.setAttribut("printView", Boolean.TRUE) and get a session variable so:
I work with struts, formbeans and jsp.
Sorry, I haven't good English and this problem is so difficult for me. So I can't declare it better at this time.

What about storing the ids of the rows clicked on a JavaScript Map, there you can change its backgound color.
Then, to submit this data to the action, just use struts + ajax (see Struts2InAction book chapter 8).
Also, if your are already uploading the data on the session context, implement SessionAware in your acction in order to be able to access session values.
Hope this help.

Related

Initialize MVC View's DisplayFor element with a value to display. Simple, right?

MVC App
I am Creating a row for a table. It is defined as a Model.
The value of one of the fields is determined during a 'login' and is available for use.
That value should be displayed when the Create view is rendered on exit from the 'create(GET)' action and it should be saved as is to the data table by the POST.
So, bound to the model and prepopulated display element sounds like a job for Html.DisplayFor. Only it seems it is not.
How do we set the initial value in the DisplayFor statement. Barring that, how do we get data to the screen from the GET action for capture and saving during the Create(POST)?
I have to write more than one of these a year.
I can just pass a populated model instance in the return View(modelInstance).
That's my stupidity quota for the day, hopefully.

Default sort for Xpages Dojo Data Grid not working on filtered values

I am trying to implement the DOJO data gird in my application. On load of the xPages I am getting the current user id in a session scope variable and filtering the REST services that supplies the data grid the data from a view, based on the user id. I have used the "keys" property to filter the values so that the current user should be able to see the values only relevant to him in the grid. This is working fine, but when I try to sort the results once the page is loaded it starts displaying blank values and sort does not work. I have made sure that the columns I require to sort are also made sorted for the back-end view by checking the "Click on column header to sort" option in the view. Still I am unable to get the sorting working for columns. Please let me know if there is a work-around for this problem or am I doing or not doing something for the default sort not to work as expected.
Nash, I have had similar issues with the blank rows as you describe. I think the blanks lines are rows that don't match the keys. Here are my tips for fixing this. The issue I think is not with your grid but your Rest service.
Use a viewJsonService type of rest service
Use a category filter instead of keys
Make your category filter code similar to mine below. This will ensure that you don't show documents to someone who shouldn't see them. When the category is null, the Rest service will show all documents. This isn't causing the blank lines, but is a best practice IMO.
var category:String = lineItemBean.getThisUNID();
//wherever your category comes from, maybe session.getUserName() in your case
if(category == null){
return "show nothing"
} else {
return lineItemBean.getThisUNID();
}
I hope this helps. My guess is that this will fix your sorting issues as well.

Concrete 5 ADODB update and insert duplicate primary key

I'm creating a new package for Concrete 5 (5.4.0+). Inserting a new block works perfectly. But when I edit an existing block, it tries to INSERT again when I click 'save', instead of UPDATE.
The two fields on the database that affect this are bID and eID. Both are non-auto-incrementing INT(10) default none NOT NULL.
The values are passed in an associative array $args in the controller and I'm calling the parent save method with Parent::save($args);
Any help/input would be appreciated. PS: I have looked over this on the net and the C5 forums did turn up some stuff which I tried, mostly relating to the database fields, but I still get the above error. I don't want to overwrite the ADODB save() method if possible.
--- EDIT ---
Perhaps I'm looking at this all wrong. Let me say what I'm trying to achieve. I need the eID to remain 37 (for example) across multiple edits of the block. The bID can increment away AFAIC.
How do I get the eID to remain 37 on edit, but increment by 1 on creation of a new instance? Make sense?
A second table references the eID field, and edited instances of an entry on this table must have the same eID unless a new instance is created. Sry - clear as mud I know.
Are you saying you get a new instance of the block appearing on your page, rather than a new version of the existing one? I don't think the problem is with there being a new record inserted in your table, since new records are normally created when you edit a block. C5 keeps the older version of the block.
The custom blocks I've done have never required a call to the parent save method. You just need an edit form that collects the data and designates which database field it corresponds to, and the parent controller knows what to do with it when the form is submitted.
For example, if you have a text field in your block table called "firstname" that you are updating, you would add a line to your edit.php file like this:
<?php echo $form->text('firstname', $firstname, array('style' => 'width: 320px'));?>
My block editors contain little else than this, other than html/CSS stuff to add labels and make the form look better. The $form object takes care of everything else.
One thing that really helped me understand blocks and block controllers was to download and install the "designer content" add-on. It's free. You can use it to build some custom blocks, then look at the code it generates to perform various functions.
So I looked into the existing packages to duplicate this funcitonality and my question has evolved into this: PHP Concrete 5 Pass Variables to Add.php
Follow the rabbit ;)

MCV3: View to edit entity has to hold every column?

I got a silly general question...
If I generate a strongly typed view of an entity and chose "edit" as scaffolding, then the view does contain every column for that table. Changing and saving the values via setting it modifierd and call db.SaveChanges() does work in the controller. So far, so good.
But if I remove just one of that columns inside the view, then saving doesn't work anymore.
Is there a rule describing this? Is it only possible to make view with every column when wanting to save the model later on? I don't want to make 90 of 100 columns "hidden"...
PS: When editing a value in another table which is connected via Foreign Key (like customer.address.STREET) saving also does not work. Does everything of the entity ADDRESS has to be inside the view? I really don't get that.
Besides that: If I create my own ViewModel containing two entities: Do they also have to hold every column of both entities? This would be a whole bunch of traffic...
Answer is: You should not use the .Modified state. Instead using the UpdateModel method works fine without every field.

List of values with multiple return items

List of values, with multiple columns and multiple return values in Apex. It's a question i've seen around the web quite a few times, but i'm struggling with it aswell.
Coming from Oracle Forms, and now migrating forms to Apex, this is a feature i'm missing quite well. It also still baffles me a bit how enormously basic the built-in popup-lov is.
For example, right now i'm making some smaller forms, each having about 4 or 5 multirecord columns, for not much else than having 2 values linked up. Column 1: some value, used in sap for example, column 2: the id of a record in the oracle database (another table than the base table for the block). On column 2 there is an lov, with validate from list, and displays 3 columns, but also returns 3 columns. So you can choose a record from the lov, and automatically, the id will be filled in, aswell as the 'name' and 'description' for said id. Column 1 and column 2 form the base table of the block.
Now, in Apex, i'd loose this functionality by default. So for now, i've mostly coded the onchange event in javascript, and get the values with an ajax callback process. In the popup i concatenate the 3 columns. This however looks stupid (in my most humble opinion) when you want to force the user to pick a value from the lov ('Not Enterable, Show Display Value and Store Return Value'): the item will contain the concatenated value used in the lov, not just the id i'd much rather show - plus, i'll already have my other 2 fields filled in by the ajax callback.
It rather stings a bit to have to deal with this. The users are used to working with these old (headstart generated) forms, with just 2 enterable columns, one of which has an lov. Now they need to start working with this 'new tech', and even though there is some adjustment required, this area does feels a bit archaic at times!
So, i've made it work through an Ajax callback on the onchange event. So, when the value is changed through the lov, extra fields are filled up. This goes together with an after header process, after the automated row fetch, so the values are fetched when the page is loaded (or a user navigates the rows).
I've also written a custom solution, which requires me to create a page with a classic report on it with a search box. I then use this page in an iframe, and pop it up through a modal. When the user selects a record, i return the required returnvalue and a list of displayvalues. This i do through a bunch of javascript, which i've packed in a JS file, and actually requires quite little extra work to do on the pages: include the file on both, make an item with some post element text calling an 'open' procedure, and calling a select-and-close procedure on my lov page. I'm quite considering creating a small item typep plug-in, so i can more easily configure my calling item. Just a couple of buts: i've not actually used this in some forms already, i've engineered this in a testing application after getting frustrated with the standard tool. It would also require the client to maintain this javascript code + remember the config of the 2 items, let alone me writing a small plugin. So i'm hesitant to implement this.
TLDR: if you've been using Apex for a while, and maybe done some forms: how do you actually work with the popups. And if you've known forms: how did you deal with this change?
I'm still struggling - throw me a bone ;)
I haven't used it myself yet but I believe SkillBuilders Super LOV plug-in probably does what you need.

Resources