Struts : Generating HTML instead of a simple message? - java

In my ApplicationResource.properties file, I can things like "welcome.message="Welcome""
and I would generate that in my jsp page with...
<h3><bean:message key="welcome.message"/></h3>
But say for example, I have a lot of html to generate, such as a list and list items for that secion...
How would I do that?

Nothing to stop you from giving the entire HTML code in the property file. For example if you want the text to appear bold you can do <B>Bold Text</B> So for your select box you can put the entire set of HTML tags in a property and set it where you want to set it.
As for dynamic content you can get a list of your objects in the action class and then use the struts UI tags to create the list or whatever you want.

Related

how to identify corresponding html object using label using java

I have html file and I have the label name now I need to identify the html object.
Can you please help me to identify the object.
I am using jsoup to parase,
I could not attaching the screen shot,
The page has top row with label below are html object
program, study, study status, study manager (all are labels and below html obj)
text box dropdown, drop down, text box (html objec)
When working with HTML, it pays to be aware of the structure of the HTML elements, and not how they are rendered on-screen. In your case, you will need to find a way to identify the elements you seek in the HTML code, and and then use one of the Document#getElement(s|)By(.+) methods to find it.

creating java help using single HTML file

I have one HTML file which contains 200 definitions and i don't want to create 200 HTML files. I want to create java help using that file such that if user click on TOC(table of content) list and user can reached at the particular definition without scrolling that html documentation.
First study how to make tree like structure using JTree and then study how to show html page in Jframe using JEditorPane.

JSF 2.0 Dynamic Views

I'm working on a web project which uses JSF 2.0, PrimeFaces and PrettyFaces as main frameworks / libraries. The pages have the following (common) structure: Header, Content, Footer.
Header:
The Header always contains the same menu. This menu is a custom component, which generates a recursive html <ul><li> list containing <a href="url"> html links, this is all rendered with a custom renderer. The link looks like 'domain.com/website/datatable.xhtml?ref=2'. Where the ref=2 used to load the correct content from the database. I use prettyfaces to store this request value in a backingbean.
Question 1: Is it ok to render the <a href> links myself, or should I better add an HTMLCommandLink from my UIComponent and render that in the encodeBegin/End?
Question 2: I think passing variables like this is not really the JSF 2.0 style, how to do this in a better way?
Content:
The content contains dynamic data. It can be a (primefaces) datatable, build with dynamic data from the database. It can also be a text page, also loaded from the database. Or a series of graphs. You got the point, it's dynamic. The content is based on the link pressed in the header menu. If the content is of type datatable, then I put the ref=2 variable to a DataTableBean (via prettyfaces), which then loads the correct datatable from the database. If the content is of type chart, I'll put it on the ChartBean.
Question 3: Is this a normal setup? Ideally I would like to update my content via Ajax.
I hope it's clear :)
It's ok to just output link yourself, commandLink is out of the question (it does a postback using javascript, it's not what you want);
Parameter are all in the param implicit object. You can insert them by a #ManagedProperty annotation, like this:
#ManagedProperty("#{param.ref}")
String ref
// .. getters, setters (obligatory!)
You can also use (if you are on JSF 2) the f:viewParam tag (a nice description http://blogs.oracle.com/rlubke/entry/jsf_2_0_bookmarability_view), you get the bonus of validation and conversion.
The way I understand it, your setup is rather complicated. Using a handwritten custom component for a menu is a huge overkill (at least judging from the provided description), a composite component would probably do. JSF has no special way of making ajax calls between views or embedding views one into another, so - unless you use iframes - your only choice would be to include all the possible pieces of content into a single view, wrapped in panels, and render them as required:
<h:panelGroup rendered='#{backingBean.ref == 2}'>
... content 2 ...
</h:panelGroup>
and so on. Careful, this would be heavy on resources.
You could also write your own ajax solution in javascript. This would require all the pieces of content to be fully independent views, with their own forms. Also, all their postbacks would have to go through ajax, so the main page does not get reloaded.

Selenium: Dynamic buttons and classes?

So, I was trying out a test case on a website and Selenium registers the events perfectly. Now, if I have to search for a particular class and get the innerHTML of that class, how would I do it assuming that I am using Java as the driving language?
Just to be more clear. I have a class like this:
<h1 class="classname">.....</h1>
I want to get the entire text between those tags.
And finally, if the ids of the buttons on the page are dynamically generated, how would I test the clicking action on them? These button, I presume are using ajax. When I click on the button, Selenium generates this:
//div[#id='c4aef94de622f51859827294']/div/div/div[1]/span[2]/span/span[3]/a
and the actual HTML of the button is this:
<a href="#" bindpoint="forward" class="ButtonForward"/>
Is it even possible to click on the button?
You could use the getHtmlSource command to get the entire HTML source, and then use something else to parse the HTML in Java and extract the contents of the target element.
You can locate elements without using an ID, for example if this is the only such button on the page you could locate it:
Using CSS locators:
selenium.click("css=a.ButtonForward");
Using XPath locators:
selenium.click("xpath=/descendant::a[#class='ButtonForward']");

How can I handle custom tags in a Java HTMLDocument?

I have a swing client that renders HTML through the use of the JEditorPane and HTMLDocument classes.
The problem I have is that I want to be able to define an area of the document as a container for some text that will be retrieved at a later date, and then use document.setInnerHTML(element, data); to swap out the place-holder content with the "real" content.
So, I decided that I would define a tag similar to this:
<html>
<body>
some text <mytag id="1>placeholder</mytag> some more text
</body>
</html>
The problem occurs when I use document.getElement(String id) - it finds mytag as an element, but it thinks it's a leaf element that has no content and so I cannot call .setInner() on it. Looking at it's parents list of elements, it thinks there are 3 - my tag has just been interpreted as individual components:
mytag (start)
content
mytag (end)
So, I'm guessing that I need to tell the document (or it's parser) about my tag, but that's where I'm falling flat as I'm fairly new to this area.
So, has anyone had any experience with this at all? I could cheat and use a span tag, but that doesn't feel right as (excluded for brevity) I also need to store an additional attribute against the tag.
Thanks in advance for your time...
It looks like you need to override the HTMLDocument to return a reader that recognises the custom tags. See HTMLDocument#getReader for more information. You'll need to return a subclass of HTMLReader which understands the custom tag (via the registerTag method).
perhaps set your detail as an attribute of your tag?
http://java-sl.com/custom_tag_html_kit.html
That shows how to add a custom tag. You can use this to write your own tags support.

Categories