Approaches for Prepopulating dropdowns in Jsp using struts.
Hi,
I'm having a functionality working of pre-populating dropdowns using struts like:
ArrayList list = getRoles(); //This method will return list of roles
request.setAttribute("roles", list);
By setting this collection in the request it will be availbel to <html:select and <html:options> tags for pre-populating. My question here is do we need to set the list (that is to be displayed in the JSP) in request scope deliberately, or there are other better approaches as well to do the same, like using expression language and accessing the method directly.
Thanks,
Prashant.
Why dont you use ActionForm.
declare a private variable
//variable
private List roles=null;
//methods
public List getRoles();
public void setRoles(List roles);and in ActionClass
ArrayList list = getRoles(); //This method will return list of roles
form.setRoles(list);This collection object will be available in the jsp forwarded from that action in the scope specified in the struts-config.
then use
<html:select>
<html:options collection="roles" labelProperty="name" property="id" />
</html:select>
Similar Messages
-
How to assign bean value to a local variable in JSP using struts.
Hi everybody!
I've a problem that puzzled me on how to assign a bean value to a local variable like String in JSP using struts.
we can have someting like this to display the value
<bean:write name="detailService" property="status" />or
<bean:define id="theStatus" name="detailService" property="status"/>
This is country: <%=theStatus%>but an error occured when I tried like this:
String currentStatus = "<bean:define id="theStatus" name="detailService" property="status"/>";
or
String currentStatus = "<bean:write name="detailService" property="status" />";Is there a way to do this?.....
Any help pretty much appreciatedJava != JSP.
The <bean:define> and <bean:write> tags are custom tags meant to appear in the HTML section of a JSP file, as opposed to the scriptlet section. They actually get turned into java code as part of the translation process.
The <bean:write> tag naturally just writes out what you tell it to.
The <bean:define> tag defines a local variable, and gives it a value.
this should do it.
<bean:define id="theStatus" name="detailService" property="status" type="java.lang.String"/>
<%
String currentStatus = theStatus;
%>With the advent of JSTL, you shouldn't really need to use scriptlet code anymore. Personally I am for 0% scriptlet code in any jsp I write. -
[b]Data Grid in jsp using Struts [/b]
I need to develop a data grid in JSP using struts .
I am using Tomcat web server , Intellij IDEA IDE.
If any one has code, please sent it.
Thanks in Advance.hi,
Use Struts-Layout datagrid framework to full fill your needs
Related Topic link
here is the clear documentation for your topic
http://struts.application-servers.com/datagrid/index.html
here is the download link
(Struts-Layout datagrid framework)
http://deltha.uh.cu/java/docs/struts-layout-1.0-docs/download.html
related discuss
http://forum.java.sun.com/thread.jspa?threadID=5202989&messageID=9811082 -
Displaying Hashmap values in JSP using struts taglib
Please can any one provide me the solution for the below query,
I have stored hasmap key as string and value as arraylist, can any one suggest how to display the hashmap values(arraylist) in table format in jsp using struts taglib.
HashMap hsMap=new HashMap();
ArrayList arrList = new ArrayList();
arrList.add("filesize");
arrList.add("filelength");
hsMap.put("filename",arrList);
In jsp i want to display filename and filesize in table format.Read this documentation:
http://struts.apache.org/struts-doc-1.2.x/userGuide/struts-logic.html#iterate -
Displaying list of items , in a jsp , using STRUTS--Correct approach
I have a requiremnet tht on click of a button , a list of items should be displayed on a jsp page , so tht a user can select items from tht list.
But the problem is tht , the list is very large(Conatins 1500 record).
So wht approach should i adopt.
One approach is tht , i have a link on my main.jsp , where user has a link (addItems) , and on clicking this link , another page(Items.jsp), opens up , where i dispaly the list of users , and user here can select multiple items , and then those items will be shown in Main.jsp.
Is this appraoch correct,
also plz tell me how can i incorporate previous and next functionality , so tht 20 records per page are shown
Can anyone tell me how 2 go abt it.
I m using STRUTS , and weblogic.Hiiii
When u want2 add textboxes dynamically,
then declare ur proprerty in action form as of type String[]
<form-bean
name="userForm"
type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="name" type="java.lang.String[]"/>
<form-bean>
When u add textboxes dynamically , and if the textboxes name is same as that in form bean,
then automatically this form bean property gets populated.
If u require further assistance do tell me -
Dynamic Textboxes in JSP using struts
Hi all
I'm using JSP and Struts framework. I have two buttons Add row and delete row.(not submit buttons) on click i need to either generate or delete a row of textboxes. I able to do the same using javascript but the tag in that case is <input..>(normal HTML) and not <html:text> tag of struts.. Can i use the struts tag in jsp?? I tried but err... So any suggestions?
A sample code would be of great help.. Im still a beginner in this ocean of Java!
cyaIf the add/delete row buttons run in javascript, then you have to use the standard <input> tags.
The struts <html:text> tag is a JSP tag that just generates an <input> at the end of the day anyway (filling in the attributes automatically though)
As long as you name the controls consistent with what would have been produced by the struts tag, it should work perfectly well. -
Display date in jsp. using struts, JSTL
want to display today's date in format October 18, 2006
how to get today's date and how to display it in jsp?
I am using struts framwork and JSTL tags in my JSP.
Thanks.rizza_99 wrote:
The page underlines {<fmt:formatDate value="${now}" type="both" dateStyle="long" />} says
attributte value doesn't accept any expressionsWait, you said "the page underlines"?? So you're using an IDE? Are you sure that it a JSTL problem and not an IDE problem? Ignore the IDE and just execute the code. Does it work without any compilation errors or runtime exceptions? If so, then there's a problem in the IDE. -
Reg : Checking for userLogin in each JSP using Filters
Hi,
To check for UserLogin in each JSP page i am using a filter.
1) -downloaded accessflt.jar
2) added the below in web.xml
<filter>
<filter-name>AccessFilter</filter-name>
<filter-class>com.cj.accessflt.AccessFilter</filter-class>
<init-param>
<param-name>attribute</param-name>
<param-value>OK</param-value>
</init-param>
<init-param>
<param-name>redirect</param-name>
<param-value>/index.jsp</param-value>
</init-param>
<init-param>
<param-name>except</param-name>
<param-value>/index.jsp</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>AccessFilter</filter-name>
<url-pattern>/faces/*.jsp</url-pattern>
</filter-mapping>
3) when User logged in Setting
session.setAttribute("OK","yes");
I am getting the below error
javax.servlet.jsp.JspException: Cannot find FacesContext
at javax.faces.webapp.UIComponentTag.doStartTag(UIComponentTag.java:427)
at com.sun.faces.taglib.jsf_core.ViewTag.doStartTag(ViewTag.java:125)
Can anybody help me please,
i will appreciate your help.
Thanks,
Sudha.Hi,
I am doing any fundamental mistake??
please anybody help or can u please tell me how to handle this situation
when user hits any JSP needs to check wether he logged in or not.
if he is not login needs to redirect to Login URL.
read the previous posts but i am not clear
please anybody help me
Thanks,
Arthi -
Multi forms from different action in one jsp using struts?
In user home page i am using 3 tabs in that 1 tab is for personal , 2 tab is for resume details etc.. but i crated for personal form1 and resumes for form2. when i click in the resume tab i have to show resumes list using same jsp. when click that tab it is showing Null pointer exception. How to solve please help.......
Read the stacktrace. The 1st line points to the class/method/linenumber where this exception is caused. Lookup this line in your code and fix it accordingly. I.e. either make sure that the object reference in question is NOT null when it is been accessed/invoked, or add a nullcheck on this object reference (e.g. if (object != null) { object.doSomething();} ) so that you can skip the action when it is null.
-
Problem in embedd ing calendar in jsp using struts framework
hi
i am working on one application which needs date as ainput and have to store in database. i have embedd one calendar coming in popup but it is working with mozila not in internet explorer. plz give me some suggestion to put this calendar on my jsp.
thanx
Gyangyan.poddar wrote:
but it is working with mozila not in internet explorerSounds like a Javascript problem rather than JSP/Java problem.
If this Javascript is generated by some JSP tag, then I would report it at the website/forum/mailinglist of the taglibrary in question. If this Javascript is just customized or some other 3rd party script, then either fix it or report it at their own website. -
How to get parameter and add it to hyperlink using struts tag?
Hi everyone:
There is a.jsp pass a parameter to b.jsp.How to get the parameter in b.jsp using struts Tag?I also want to add the parameter to a hyperlink in b.jsp.For example in b.jsp <html:link forward=.....>cxxxx</html:link>.How to add the parameter(get from a.jsp) to cXXXX in b.jsp?Try this:
Copy A Request Parameter - You can create a new bean containing the value of a parameter included in this request. If no parameter of the specified name was included, a request time exception will be thrown - therefore, it is common to nest the use of this tag inside a <logic:present parameter="xxx"> tag to ensure that the parameter was really included. If there is the possibility that more than one parameter of the same name was included, specify the "multiple" attribute (and the resulting value bean will be an array of String values, instead of a single String).
<bean:parameter id="name" name="name"/>
And then just use <html:link> with paramId. No java code at all. -
Saving results displayed on jsp into a text file using struts actions
Hi,
i am developing a web application using struts...the basic functionality of the system is to retrieve data from the database based on the search conditions given by the user. Hence for different search criteria there are different JSP result screens. Struts and persistence are being used. The user should be able to save/view the data loaded on the screen in a text file when he clicks on the save button.
I am supposed to write an action for fileoutput which can be used by all the result screens...instead of writing the same code in all the jsp pages...how do i go about it? I have already written an action class for the same but when i click on the save button a blank IE screen opens up instead of the open /save dialog box...i have also added mappings for the same in struts config xml file....any suggestions?Again, you have posted to the wrong board. SignalExpress is an application written in LabVIEW.
-
Using struts - jsp design question
Using struts. Have a JSP cust.jsp
In it half of it is very specific to that page only. rest half is shown in this cust.jsp and another report.jsp too.
want to implement this so that code can be re-used in the other one too.
The way I have designed is for a jsp have a prepare action and dispatch action.
But not sure how to design this page so that I can re-use the code in another too.
any suggesions are appreciated.
Thanks.have a look at frameworks like Struts
-
Display HashMap values in JSP using Taglib in struts
Hi ,
I am new to struts and JSTL. I am developing Discussion Forums using Struts.
I have HashMap object with(key & values) in My Action class.
I want to diplay in my JSP as a List with html:links to do other process.
How can I display HashMap values in my JSP. Which is the best way to display
My intenetion is maxmum avoiding <%%> code in jsp.
Which is the best way to display ?
Can I diplay using taglib which is generic tag for any collection object ?
Can any one help me ASAP.
thanks
ChandraHi Riaz,
You can use same code in JSP
Java Code
import java.util.*;
class TestHashMap
public static void main(String args[])
HashMap hm=new HashMap();
//store some Objects.
hm.put("Rajib Sarma","100");
//duplicate keys are not allowed.
hm.put("Rajib Sarma","200");//The value "100" is replaced by "200".
hm.put("Sazid Ahmed","200");
//Display the contents of the HashMap
System.out.println("Displaying all the keys/values.\r\n");
System.out.println("Key\t\tValue\r\n");
//get all the keys
Collection c=hm.keySet();
//obtain an Iterator
Iterator i=c.iterator();
while(i.hasNext())
//obtain a key
Object key=i.next();
//obtain the value of the key
Object value=hm.get(key);
System.out.println(key +"\t" + value);
}//while ends
}//main ends
} -
Question of using Struts for the J2EE pattern
I am now using Struts for the development. I have 3 questions about J2EE
pattern by the use of Struts:
1) How can I use Struts to create the Front Controller? In the book
descibing Front Controller, it is a servlet file which receives the request
and then dispatches to the appropriate view according to the request.
However, in using Struts, should I use the same way? However, I found that
in using Struts, I can call the controller class which subclass
ActionServlet, all the views forwarded are declared in the
struts-config.xml. Am I right in this method?
2) In the project, there is a Front Controller which dispatches the request
to the appropriate view (jsp file). Of course, I use Struts to do this.
However, I expect that the user is impossible for going to the view (jsp
page) directly by typing the address of the jsp file. I hope that the user
can go to the view through the controller only. How can I do this?
3) There is a problem by using browser - when a user browses a site, he can
press the 'back' button to the previous page, and then click the 'forward'
button also. How can I prevent this by using Struts? I found that in some
sites, when the user clicks the 'back' button, an error page displays. How
can I do this? Thanks!
Many Thanks!
StephenI'll take a stab at number 2 and number 3.......
2) You could have the controller object place a "flag" in the request that is dispatched to the JSP. Make the JSP check for that flag to ensure that this request came from the controller object. If the request comes from anywhere other than the controlle object, you can display an error page, or you could redirect them back to the controller. You could also use the HTTPSessionObject to place flags for users and have the JSP check there.
3) Keep a log of the user's activities in the HTTPSession. Whenever a page is invoked, have it check to see if the user has already been here, and if it is appropriate for the user to be here again.
Hope this helps!!
I'm not really a java programmer, I just play one on TV.
Maybe you are looking for
-
What forum might be useful in solving this issue: Simple Examples of data connectivity and transfer of data from an .asp.vb to javascript in an .aspx file
-
MacbookPro Retina how to use NVIDIA display
How to do I use NVIDIA display for my MBP Retina 15"? I tried Apple -> About this Mac -> More Info -> Display and I am unable to select NVIDIA display, only the Intel HD display shown. Please help what should I do?
-
How to pass a object of JSP to a servlet called from JSP
Hi, I am trying to display an image in the JSP through html image tag. I am using Struts Action class to get the image data from the database through a Session EJB. I am getting a byte array for the image retrieved from the database. To display the i
-
Destiny Vanguard Armory Pre order bonus
Bungie recently revealed that when you pre order Destiny you receive access to the vanguard armory. When I went to check the Destiny page at Best buy.com, there was no mention of it. Will people who will or have pre ordered Destiny receive this conte
-
Hi, I'm using Robohelp 7.0.2 and I'm having problems getting Japanese and Chinese characters to display correctly in the TOC of my project. My HHC and HHK files are correctly encoded as UTF-8 and show up correctly in the main Robohelp interface. My t