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.
Related
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'}
I have a form in Struts 1.2 where I have text boxes (text box created using struts html tag) . I have retrieved the values for this text box from data base and then put in session attribute (session.setAttribute("UserInfo",userinfoobj)) now I wants to get values from session attribute and set this value as value of text box
Best way would be to use a form-bean to hold the values of your input fields and then bind this form bean to your JSP page using struts configuration. Populate this form bean and then set it in session or request scope. Struts will handle the values (for capturing and rendering) behind the scene automatically if you use appropriate struts tags.
Pls google how to use ActionForm with struts 1.x
EDIT: here is simple example on how to do this http://www.raistudies.com/struts-1/login-form-with-struts-1/
Use OGNL stack.
Use this: value="parameters.<your request variable name>".
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.
One thing I learned today is "there is no selected property in
<html:option>
like plain old option" , we can give value in
<html:select>
that matches the value against each option and if match found marks the option selected.
but I want to make multiple options pre-selected on page load(am using
<html:select multiple="true">
How can it be achieved?
Implement the following:
If possible use JavaScript to make the selected entries true for the
multiple entries u had made in that select list
Make it selected by using Java-script first by calling javascript
function before any action OR with that action :
function callSelectAll(selectName)
{
var i;
for(i=0;i<...) {
document.getElementById(selectName).options[i].selected = true;
}
}
And use String[] array name as a property name for that html:select property form bean property. And the name of that array as a property of that html:select in jsp page.
You will ultimatly gate the all selected values un the that string array of form bean.
i'm doing a JSF2 project.
1 . i have a form with some checkbox. Look the following code
<ui:repeat>
<h:selectManyCheckbox value="#{wagent.selectedPra}">...
</h:selectManyCheckbox>
</ui:repeat>
So i use selectManyCheckbox inside ui:repeat and i want that the value of the different selectManyCheckbox point to the same value.
But when the form is submit i didn't have all the selected boxs.
How i can do that ?
2 . I have a form with some inputs. On my action i want to merge some pdf files, stay on the same page and that a pop-up appear to offer to download the merged files.
3 . Does all the managed beans with request scope are created for each request or just if i used them in the xhtml page?
4 . I have a commandlink to logout. On my action i use session.invalidate() and return "login". So i go back to the login, but when validating the login, my session managed bean doesn't seem to be created. Error is something like yourSessionBean is null. What's wrong ?
1: So i use selectManyCheckbox inside ui:repeat and i want that the value of the different selectManyCheckbox point to the same value. But when the form is submit i didn't have all the selected boxs. How i can do that ?
Let them point to a different value instead. With the given example the bean value will be overridden everytime until end of the loop. As an example, use a List<List<Pra>> in a bean (or whatever Pra means in your question):
<ui:repeat value="#{wagent.allSelectedPra}" var="selectedPra">
<h:selectManyCheckbox value="#{selectedPra}">
...
</h:selectManyCheckbox>
</ui:repeat>
2: I have a form with some inputs. On my action i want to merge some pdf files, stay on the same page and that a pop-up appear to offer to download the merged files.
At least two things needs to be done:
facesContext.getExternalContext().addResponseHeader("Content-Disposition", "attachment;filename=name.pdf"); // Force "Save As" dialogue.
facesContext.responseComplete(); // Prevent JSF from taking response in hands.
3: Does all the managed beans with request scope are created for each request or just if i used them in the xhtml page?
They are created for every HTTP request. The scope which you described only applies on view scope (if I understand you right).
4: I have a commandlink to logout. On my action i use session.invalidate() and return "login". So i go back to the login, but when validating the login, my session managed bean doesn't seem to be created. Error is something like yourSessionBean is null. What's wrong ?
You are probably accessing the session scoped managed bean the wrong way. You need to either inject it as #ManagedProperty or to grab it by Application#evaluateExpressionGet().