Make dynamically created AttributeDefImpl read only after it is populated - java

I am new to using the ADF framework. I am dynamically creating view objects that appear on a JSF front-end page. I want to create a dynamic view on the front end that cannot be edited once it is populated and rendered. My code is as follows:
AttributeDefImpl dynamicViewAttribute = dynamicViewDef.addViewAttribute(name, alias, javaType);
dynamicViewAttribute.setUpdateableFlag(AttributeDef.READONLY);
This fails as once the view object is set to READONLY, it cannot be updated. If I change the line of code as follows:
dynamicViewAttribute.setUpdateableFlag(AttributeDef.UPDATEABLE);
There is no error and the page displays correctly, but the user can edit/update the text in the view object.
How can I accomplish what I need i.e. display the view object text without letting the user edit/update it? Remember this has to be dynamically created so I cannot set readOnly=true on the jsf.

If this will be dynamically determined , then you can send your flag or Attribute i.e ("IsReadOnlyFlag") in the ViewObject.
in your jsf page change the attribute readOnly for
the inputText to readOnly=#{bindings.IsReadOnlyFlag.inputValue eq 'Y'}

Related

How to maintain the contents in the text field after redircting to same page jsp.

Hi I have jsp page That is having some text fields,I will fill that text fields and I will submit that form to server side.If any error comes in the server side I will redirect to the same page with error message Now I want that text field to remain as it is but in my case it is clearing.How to make the text field as same.
The two options available to you are:
Don't reload the page. Instead submit the data via AJAX or validate it by javascript. That way you don't ever have to touch the data in the form. Make sure your javascript highlights the fields that have errors in some way.
The endpoint that you're POSTing your data to needs to be able to recognise that the data is invalid and include that data when returning the user to the same page. I'm not familiar with jsp, but generally you'd do that by including variables in your template for your form that could contain the data, and passing empty strings on the first load of the page. If the page is then shown to the user again after a failed form validation, pass back the POST data that you received in your form request.
There are two option, you can dispatch the request/response to the same page instead of redirect, but you need to add an attribute and recover it in the JSP, or you can add the attribute in the session , recover the value to de text field and remove it using (if you are using JSTL)

Play Framework 1.2.4: Selected Option for #{select} template

I am passing a Model and a List<String> from controller to .html file using the render method invocation. The Model passed contains some values that has to be populated in different components present in the UI and the List<String> is used for binding with the combo-box.
For binding the List<String> with combo-box in the .html using the below code and this is working fine:
#{select 'employee.role', items:userRoles, valueProperty:'userRoles', labelProperty:'userRoles'/}
What I want to achieve:
Suppose the List<String> contains the roles as Trainer, Educator, Trainee, Staff and the Model passed has a role property with value Staff. When the page loads, then Staff should be in selected state in the combo-box display.
Problem
I am aware of how to iterate through a List in Play framework template but I am not aware of how to keep a value selected in the drop-down based on one of the property values present in the Model
Kindly help me on this.
From the documentation:
This tag can generate options using items attribute.
items (optional) - list of objects, used to create options
value (optional) - selected element in items (note that multiple selections are not supported)
labelProperty (optional) - for each item, attribute used as option’s label
valueProperty (optional) - for each item, attribute used as option’s value. id is used by default
So, the code should be:
#{select 'employee.role', items: userRoles, value: model.role /}

issues passing dropdown value to java

I have a bunch of select tags in my page where some of them allows the user to use the dropdown and some of them will be disabled at a given time. so I have a select tag in my jsp such as:
<html:select name="myobject" property="myfield" disabled="$(isDisabled ? 'disabled' : '')"/>
I wanted to set as readonly a select tag on my jsp but apparently is not possible so I had to put disable. Since disabled values are not passed back to the application when a user submits the action I created a hidden object of it to pass it as it's suggested everywhere to work around that...
<html:hidden name="myobject" property="myfield" indexed="true"/>
The problem is.. when the form is submited I don't get the new dropdown value selected by the user, I debug into my java code and what I receive is the value that was originally sent to the page instead of what the user picked. It works if I removed the hidden field but if I do so then the disabled selections won't displayed when refreshed cause disabled fields don't pass back the values and i'll receive null at my end... how do I fix this problem?
Thanks,
There may be a duplicate of name or property of the html hidden component.

JSF, How to set a property in a different page/backing bean and then navigate to that page?

I am using JSF 2.0 and attempting to pass values between different pages in my App.
The setup is as follows:
I have a page called userSelect that has a backing bean userSelectBacking. On this page I display a list of users that can be selected and submit using an h:commandbutton, when the page is submit the navigation goes to a userEdit page.
I have a page called userEdit, that has a backing bean userEditBacking which displays the information for a user
and allows that user to be edited.
I would like to pass the user selected from the userSelect page into the userEdit page.
I am currently using f:setPropertyActionListener to set the user in my userEdit backing from the userSelect page, however when I navigate to the userEdit page, it loses the information I set.
is there a way that I can pass the values between the two pages/backing beans?
thanks
I am currently using f:setPropertyActionListener to set the user in my userEdit backing from the userSelect page
It should work.
however when I navigate to the userEdit page, it loses the information I set.
This will happen if the data loading logic is wrong, or you fire a redirect afterwards while the bean is request scoped.
To fix the data loading logic, just ensure that in case of a request scoped bean the same datamodel is preserved in the subsequent request. Usually you use the bean's constructor or lazy loading in the getter for this. If that is not an option, then you need to put the bean in a bit broader scope, e.g. #ViewScope or #SessionScope.
To fix the redirect issue, either just don't fire a redirect (i.e. remove <redirect/> from navigation case, or don't call ExternalContext#redirect()), or put bean in a broader scope.

Implementing dynamic pagesize in pagination struts2 + java

I am trying to implement pagination through display tag in Struts2.
Now my requirement is I have a combo box which has some page size value like 5, 10, 15 ..
So, How can I update that value in page size of display tag in Struts2 ?
You would create an exposed property on your action, named for example selectedPageSize. This property could be set to a default size (in your example 5). You would keep a hidden form field storing the currently selected value. This would then be used in your view with the display tag similar to:
<c:set name="selectedPageSize" value="selectedPageSize" scope="request"/>
<display:table pagesize="${selectedPageSize}" ... >
I'm not sure about struts2 in particular, but with JSF in general, if you bind whatever component you use to paginate into your backing bean, you can set properties such as that through an action.

Categories