Is there any way to define a new tiles definition file other than the tiles.xml file at runtime (say tiles2.xml) and use it? I want to create a tiles2.xml using Java when a action is called. Or, can I pass the filename.jsp as a parameter to tiles.xml during runtime?
Here is what I am trying to do.
There are 50 menus. When any of the menus is clicked, parameters regarding the menu name are passed through an action to a Java class. The class checks and finds which file to open. Now, either I can pass that value to tiles.xml or create a new tiles definition file.
Please help. Thanks
Related
I'm trying to create a DXL script that will take all the objects from select set of modules and combine them into a new module which will then be exported to Excel.
The issue I'm having is I can't figure out how to get objects from a module that isn't open. I'm open to any method but I've been trying to use ModuleHandles. Most of the examples I've seen are for moving objects within the current module.
You need two variables of type Module, one for the source module (e.g. mSrc), one for the target module (mTgt). Use the command read for opening the source module and setting the resulting handle to mSrc. Use edit (or create) for opening the target module and setting the resulting handle to mTgt.
Then use a variable of type Object for iterating over all objects of mSrc (for oSrc in mSrc or perhaps ... in entire mSrc, depending on how the views in your source modules are set up), create objects in the target module (to a variable oTgt of type Object) copy the object attributes that you need from oSrc to oTgt. For the latter there is a function copyAttribute_ in copyops.inc.
If you want to replicate the hierarchy of the source module, you will need loops of type for Object in Object and commands like create after create below etc.
Perhaps there are already scripts available in IBMs DXL Forum or on some of the web sites that provide a solution for your problem.
I am using Intellij IDEA and Grails as my application framework.
My application is mainly on Groovy.
I am trying to add external custom argument as an external parameter to my application.
I have opened the Edit Configurations... and tried different ways to add custom arguments in the VM options, and inside the Program Arguments, but with no success.
Here is an example to one try I did:
I added
-Dcustom.arg=100
to the VM options.
I would like to know if it is possible to inject external variable by using the Application configuration?If yes, how should it be done?
It should be done by adding a new program argument to the Edit configuration --> Program Arguments:
Just add a new value of the custom argument such as: externalArg.
And in the application code, find the section read those properties.
For example:
Properties props = System.properties
String propValue = props.get("sun.java.command").toString()
the propValue contains all the Program Arguments and specifically the externalArg parameter you have inserted.
Another option can be done by inserting the variable into the Edit configuration --> VM Options. When using grails, the parameter should look like that:
-Dgrails.externalVariable=3
Reading the externalVariable inside the application is done by:
Object externalVariable = System.getProperties().get("grails.externalVariable")
Note:
Both of those 2 options give the same result.
Using each one of the options should be related to the variable concept.
If you wish to have the externalVariable as a program argument insert the parameter into the Program Arguments.
If you wish to have the externalVariable as a Virtual machine parameter insert the parameter into the VM Options.
I have one property file linked both ways (using f:loadBundle and faces-config.xml) both with different var names. So it would look like the following:
datatypes.properties:
A=first
B=second
C=third
faces-config.xml:
<resource-bundle>
<base-name>datatypes</base-name>
<var>myProp</var>
</resource-bundle>
myPage.xhtml:
<f:loadBundle basename="datatypes" var="prop"/>
in myPage.xhtml I make a list of all the keys from the property file. What I can't seem to understand is that when I use #{prop} in the code below it works but when I replace it with #{myProp} the list no longer displays.
<h:form>
<h:selectManyListbox id="list">
<f:selectItems value="#{myProp}"></f:selectItems>
</h:selectManyListbox>
</h:form>
I figure this means the variables in both cases are not the same behind the scenes but I would appreciate it if someone could explain (or point me to an explaination) in what way they are different. I would ideally like to just use #{myProp} without having to pull the keys out in code and store them in a list.
Thanks.
Both <f:loadBundle> and <resource-bundle> are different ways to load properties with difference being in their access scopes. The latter has by the way the additional benefit that the bundle is also injectable in a managed bean by #ManagedProperty("#{myProp}")
Using <resource-bundle> in faces-config.xml creates a global resource bundle which can be accessed anywhere in your application. This is implemented through a java.util.ResourceBundle instance.
Using <f:loadBundle> in your view creates a view-specific resource bundle which is accessible only within that view. The tag handler implements this using an internal implementation of a Map. This is as specified in the VDL of the tag:
Load a resource bundle localized for the Locale of the current view,
and expose it as a java.util.Map in the request attributes of the
current request under the key specified by the value of the "var"
attribute of this tag.
Now since you're trying to use the values from datatypes.properties through <f:selectItems>, you'll get the said exception. This is because the value attribute for the tag should evaluate to a Collection or an array.
Value expression pointing at any Collection or array. The member
elements may be instances of SelectItem or any Java Object.
So in order to use the global bundle instance, you first have to convert the same into a List<SelectItem> inside your backing bean before using it.
NOTE: You can verify the above cases by setting a breakpoint in the initializeItems(Object) method in the com.sun.faces.renderkit.SelectItemsIterator class. This is, of course, assuming that you're using the Mojarra implementation.
I have an image present inside the images folder of my war, and my action class is at war/WEB-INF/classes/some_package. I wish to access that image inside my action class. I believe I can do it by using ServletContext.getResourceAsStream("images/my_image.png") (as it takes the war folder as the base), but is there a more direct way of doing that in Struts2 ?
No, that is how you access class path resources, which is unrelated to Struts.
You may use a "stream" result type to send it back to the client, however.
I am using a third party JSF 2.0 component (the Primefaces 3.0 FileUpload) that defines its own custom event. On the server side, the signature of the handler looks like this:
public void handleFileUpload(FileUploadEvent event)
Problem is, my form is built dynamically and may have dozens of separate FileUpload controls in it, and I need to know WHICH of the fileupload controls generated the event.
Actually, I don't need to know which, I just need the "var" that was in the ui:repeat that caused that particular FileUpload control to be generated. With normal controllers I could have easily just passed in the variable I need, but this 3rd party component happens to use an event handling mechanism rather than a controller, and being rather ignorant of how to work with JSF 2.0 events, I don't know how to get at the POJO, given only the event.
I see that event has a getComponent() method on it that tells me the UIComponent, but after poking around I don't see any easy way to get at the contextual variables, or even a way to generate my own EL expression to evaluate to get at the contextual variables.
So the question boils down to... given only an event, how can I get at the contextual variables in scope for the particular component that was clicked?
Figured it out... I needed to put this inside the 3rd party component
<f:attribute name="myObject" value="#{myObject}"/>
Then it is available in the attributes map of the component on the server side:
final MyOjbect myObject = (MyObject) event.getComponent().getAttributes().get("myObject");