我在做个项目 碰到了问题 希望大家提示一下
caqis
2011-11-07
我从后台数据库 动态(用户输入关键字)查询了一段文本 到网页上显示 , 使用了 jsf的 <h:outputLabel value="${mybean.string}" />输出 我想实现 的功能是 : 用户输入关键字 在 ${mybean.string}的文本中 高亮显示,方便用查看! ( 我用 fn:replace 函数 输出不了 ) 各位能给个提示 或者实现方法吗!! |
|
mfkvfn
2011-11-10
后台replaceAll不行吗?
|
|
asyty
2011-11-10
js不行么?
|
|
kidneyball
2011-11-10
思路:
1. 使用<h:outputText value="${mybean.string}" escape="false"/>, 然后 2. 在你的mybean.getString()里: 2.1 先把你的string里的小于号换成<,大于号换成>,&号换成& 2.2 用replaceAll把你的关键字换成<font color=xxx>关键字</font> 2.3 返回string |
|
caqis
2011-11-10
感谢大家的回复
(我使用的netbean jsf web) 按照以上各位仁兄的思路 先考虑在后台修改 我在取出数据库记录列表的时候修改 。。。。。。BookCopy1(和数据库表对应的 实体bean) TypedQuery<BookCopy1> query = em.createQuery(cq1); 构建(cq1条件)查询 List<BookCopy1> rows = query.getResultList(); 得到查询结果列表 String okstring1 = "<span style= \"color:red \"> 泽泻汤</span>"; 要替换的关键字的字符串 for (int i = 0; i < rows.size(); i++) { 替换每条记录中的字段中的关键字 (1) 如果使用 java的字符处理函数 rows.get(i).getBookneiron().replaceAll("泽泻汤", okstring1); 或者用 replace("泽泻汤", okstring1) 都得不到想要的结果,仍然没有高亮显示出来 } (2)如果 使用数据库实体bean BookCopy1 其中的 setBookneiron()方法 结果是永远都显示了红色 string kk=rows.get(i).getBookneiron().replaceAll("泽泻汤", okstring1); rows.get(i).setBookneiron(kk); 使用 bean的设置属性的方法 原因是 把所有都在数据库里面查询到的记录 其中的 值(泽泻汤) 的内容都 被替换成了 <span style= \"color:red \"> 泽泻汤</span> 我很疑惑 这里调用setbean 方法 缺把数据库的记录修改了?? (如实在没办法打算 下一步用下js) |
|
kidneyball
2011-11-11
你直接改实体bean里的值吗?你查查数据库里的记录有没有被改不就知道了。如果确实被改了,你就把实体bean里的字符串先复制(赋值)到backingbean里再操作。
|
|
caqis
2011-11-11
在for循环里面new 实体bean 再去操作新建的实例对象的 set方法 等等,果然问题解决了
|
|
caqis
2011-11-11
我想这种方式在后台操作字符串 对服务器的要求应该要高点
|
|
caqis
2011-11-11
glassfish 报错 但是能够查询 出结果
警告: WEB0517: Unable to restore sessions for web module [/WebApplication2] from previous deployment java.lang.ClassCastException: cannot assign instance of java.lang.String to field d.BookCopy1Controller.items of type javax.faces.model.DataModel in instance of d.BookCopy1Controller at java.io.ObjectStreamClass$FieldReflector.setObjFieldValues(ObjectStreamClass.java:2050) at java.io.ObjectStreamClass.setObjFieldValues(ObjectStreamClass.java:1228) at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1970) at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1888) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369) at org.apache.catalina.session.StandardSession.readRemainingObject(StandardSession.java:1951) at org.apache.catalina.session.StandardSession.readObject(StandardSession.java:1859) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:991) at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1866) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369) at org.apache.catalina.session.StandardSession.deserialize(StandardSession.java:1144) at org.apache.catalina.session.StandardManager.readSessions(StandardManager.java:492) at com.sun.enterprise.web.WebModule.loadSessions(WebModule.java:1573) at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2002) at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1651) at com.sun.enterprise.web.WebApplication.start(WebApplication.java:109) at org.glassfish.internal.data.EngineRef.start(EngineRef.java:130) at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:269) at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:294) at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:462) at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240) at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:382) at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:360) at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:370) at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1064) at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:96) at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1244) at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1232) at org.glassfish.deployment.admin.ReDeployCommand.execute(ReDeployCommand.java:126) at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:355) at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:370) at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1064) at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:96) at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1244) at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1232) at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:459) at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:209) at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:168) at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:238) at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828) at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725) at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019) at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225) at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90) at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79) at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54) at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59) at com.sun.grizzly.ContextTask.run(ContextTask.java:71) at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532) at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513) at java.lang.Thread.run(Thread.java:722) |
|
ywlqi
2011-11-16
个人比较喜欢js方案
|